<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions"
           prefix="fn" %>
<script type="text/javascript">
    function doAjaxCallBackForRoleMenuDialog(json) {
        if (json.code == 0) {
            $(this).alertmsg('ok', '保存成功！')
            $(this).navtab('refresh');
            $(this).dialog('closeCurrent');
        }else {
            $(this).alertmsg('error', '保存失败！')
        }
    }

    $.CurrentDialog.find("#addForm").submit(function () {
        var menu = [];
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo2");//获得树对象
        var checkNodes = treeObj.getCheckedNodes(true);//勾选的节点
        for (var i = 0; i < checkNodes.length; i++) {
            menu.push(checkNodes[i].id)
        }
        $.CurrentDialog.find("#menus").val(menu);
    })
</script>
<form action="role/changeRoleMenuSubmit.shtml" class="pageForm"
      data-toggle="validate" data-callback="doAjaxCallBackForRoleMenuDialog"
      method="post" id="addForm" data-toggle="ajaxform">
    <input type="hidden" name="role" value="${role.id}">
    <input type="hidden" id="menus" name="menus">
    <div class="bjui-pageContent">
        <div class="panel panel-default">
            <div class="panel-body" style="padding-left: 50px;">
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label>角色名称</label>${role.name }
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label>角色类型</label>
                            ${role.type}
                        </div>
                    </div>
                    <div class="col-md-12" style="height:300px;overflow-x:hidden; ">
                        <ul id="treeDemo2" class="ztree"></ul>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <div class="bjui-pageFooter">
        <ul>
            <li>
                <button type="submit" class="bt-primary">提交</button>
            </li>
            <li>
                <button type="button" class="btn-close">关闭</button>
            </li>
        </ul>
    </div>
</form>
<script type="text/javascript">
    var zNodes = ${treeNode};
    var setting = {
        check: {
            enable: true,//设置zTree的节点上是否显示checkbox/radio框，默认值: false
            chkboxType: {"Y": "ps", "N": "ps"}
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pid",
                rootPid: 0
            }
        },
        key: {
            checked: "checked"//zTree 节点数据中保存check状态的属性名称。默认值："checked"
        },
        view: {
            selectedMulti: true//允许选多个
        }
    };

    $(function () {
        $.fn.zTree.init($("#treeDemo2"), setting, zNodes);
    });
</script>